package com.yx.enterresourceplanning.service.serviceImpl;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class TokenServiceImpl {
    private final RedisTemplate<String, String> redisTemplate;
    public TokenServiceImpl(RedisTemplate<String, String> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }
    //存储token
    public void saveToken(String tokenKey, String tokenValue,long expiration, TimeUnit unit) {
        redisTemplate.opsForValue().set(tokenKey, tokenValue, expiration, unit);
    }
    //验证token
    public boolean validateToken(String tokenKey, String expectedtokenValue) {
        String storedToken = redisTemplate.opsForValue().get(tokenKey);
        return expectedtokenValue.equals(storedToken);
    }
    //删除token
    public void deleteToken(String tokenKey) {
        redisTemplate.delete(tokenKey);
    }
}
